package com.bing.config;

import com.alibaba.excel.converters.NullableObjectConverter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;

import java.util.Objects;

/**
 * @author Administrator
 */
public class WorkStatusConverter implements NullableObjectConverter<Integer> {
    @Override
    public Class<Integer> supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.NUMBER;
    }

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return cellData.getNumberValue().intValue();
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        if (Objects.isNull(integer)) {
            return new WriteCellData<>("");
        }
        // 下面两行代码可以提取枚举字段名，枚举转换可以写在一个类里，但是sonarLint会报红，
//        String[] fts = excelContentProperty.getField().toString().split("\\.");
//        Console.log(fts[fts.length-1]);
        switch (integer) {
            case 1:
                return new WriteCellData<>("在岗");
            case 2:
                return new WriteCellData<>("休假");
            case 3:
                return new WriteCellData<>("待岗");
            case 4:
                return new WriteCellData<>("离岗");
            default:
                return new WriteCellData<>("");
        }
    }
}
